import axios from './axios.js';

export default {
    namespaced:true,
    state: {
        username: ''
    },
    actions:{
        /**
         * 新增流程
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async addAssistantApi({commit, state}, params) {
            try {
                let {data} = await axios.post('/api/cases/assistant/add', params);
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
		/**
         * 修改流程
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async editAssistantApi({commit, state}, params) {
            try {
                let {data} = await axios.put('/api/cases/assistant/edit', params);
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
        /**
         * 查询诉讼详情(流程，信息)
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async caseDetailsApi({commit, state}, params) {
            try {
                let {data} = await axios.get('/api/cases/assistant/details', {params});
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
		/**
         * 结案 (✿✿ヽ(°▽°)ノ✿)
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async endCaseApi({commit, state}, params) {
            try {
                let {data} = await axios.post(`/api/cases/assistant/end?case_id=${params.case_id}`);
				console.log(data);
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
		/**
         * 更新流程节点 (将该节点设置为当前流程)
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async freshCaseApi({commit, state}, params) {
            try {
                let {data} = await axios.post(`/api/cases/assistant/fresh?process_id=${params.process_id}`);
				console.log(data);
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
        /**
         * 查询我的案件
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async myCaseApi({commit, state}, params) {
            try {
                let {data} = await axios.post('/api/cases/assistant/my', params);
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
		/**
         * 查询未安排助理的案件
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async noneInspectApi({commit, state}, params) {
            try {
                let {data} = await axios.get('/api/cases/assistant/none', {params});
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        }, 
		/**
         * 删除该流程 (不能删除初始流程和已经开始的流程,若要删除请先更新流程节点)
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async delProcessApi({commit, state}, params) {
            try {
                let {data} = await axios.delete('/api/cases/assistant/process', {params});
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        }, 
		/**
         * 助手上传案件资料
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async uploadFileApi({commit, state}, params) {
            try {
                let {data} = await axios.post('/api/cases/assistant/upload', params);
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
		/**
         * 线下支付
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async litigationPayApi({commit, state}, params) {
            try {
                let {data} = await axios.get('/api/cases/litigation/pay', {params});
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
		/**
         * 线下支付
         * @param commit
         * @param state
         * @param params 请求参数
         * @return {Promise<*[]>}
         */
        async webofficeApi({commit, state}, params) {
            try {
                let {data} = await axios.get('/api/account/weboffice/url', {params});
                return [null, data]
            } catch (e) {
                return [e, null]
            }
        },
		
    },
    mutations:{
        /**
         * 设置用户名
         * @param state
         * @param data
         */
        setUsername(state, data){
        	console.log(data)
            state.username = data;
        }
    }
}
